<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <!-- 快速新增标准明细 -->
          <a-col :span="24">
            <a-form-model-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="">
              <a-button @click="speedAddtandardItem" type="primary" icon="plus">快速新增标准明细</a-button>
              <span style="color: #dd1820;margin-left: 10px;"> * 适用于分项结构一致的标准明细等</span>
            </a-form-model-item>
          </a-col>

          <!-- 快速新增标准明细 modal -->
          <div>
            <a-modal title="快速新增标准明细" :visible="speedAddStandardItemVisible" @ok="speedAddStandardItemOk()" @cancel="speedAddStandardItemVisibleCancel" width='70%'>
              <a-row>
                <a-col  :span="12">
                  <a-form-model-item label="所属考试" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="examinationId">
                    <j-dict-select-tag v-model="changePaperItemParams.examinationId" @change='examinationIdChange' style="width: 100%;" placeholder="选择所属考试" dictCode="ach_examination,examination_name,id"/>
                  </a-form-model-item>
                </a-col>
                <a-col  :span="12">
                  <a-form-model-item label="目标试卷" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="examinationPaperId">
                    <a-select v-model="changePaperItemParams.examinationPaperId" placeholder="选择对应的目标试卷" style="width: 100%;"
                              :getPopupContainer="(target) => target.parentNode" @change='speedAddPaperIdGetScoreChange(changePaperItemParams.examinationPaperId)'>
                      <a-select-option v-for="item in paperListData" :key="item.value">{{ item.label }}</a-select-option>
                    </a-select>
                  </a-form-model-item>
                </a-col>

                <a-col :span="12" style='border-bottom: 1px solid #d9d9d9;margin-bottom: 10px;'>
                  <a-form-model-item label="所属上级标准" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="achievementStandardId">
                    <j-dict-select-tag type="list" v-model="speedAddStandardItemModel.achievementStandardId = this.modelDefault.achievementStandardId" disabled style="width: 100%;"
                                       dictCode="ach_achievement_standard,achievement_standard_name,id" placeholder="请输入所属上级标准" />
                  </a-form-model-item>
                </a-col>
                <a-col :span="12" style='border-bottom: 1px solid #d9d9d9;margin-bottom: 10px;'>
                  <a-form-model-item label="科目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="subjectId">
                    <!--              <a-input v-model="model.subjectId" placeholder="请输入科目id"  ></a-input>-->
                    <a-select v-model="speedAddStandardItemModel.subjectId = this.modelDefault.subjectId" placeholder="请选择所属科目" disabled  style="width: 100%;"
                              :getPopupContainer="(target) => target.parentNode">
                      <a-select-option v-for="item in subjectList" :key="item.value">{{ item.label }}</a-select-option>
                    </a-select>
                  </a-form-model-item>
                </a-col>
<!--                <a-col  :span="12">-->
<!--                  <a-form-model-item label="所属考试" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="examinationId">-->
<!--                    <j-dict-select-tag v-model="changePaperItemParams.examinationId" @change='examinationIdChange' placeholder="选择所属考试" dictCode="ach_examination,examination_name,id"/>-->
<!--                  </a-form-model-item>-->
<!--                </a-col>-->
<!--                <a-col  :span="12">-->
<!--                  <a-form-model-item label="目标试卷" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="examinationPaperId">-->
<!--                    <a-select v-model="changePaperItemParams.examinationPaperId" placeholder="选择对应的目标试卷"-->
<!--                              :getPopupContainer="(target) => target.parentNode" @change='examinationPaperIdChange'>-->
<!--                      <a-select-option v-for="speedAddStandardItemModel in paperListData" :key="item.value">{{ item.label }}</a-select-option>-->
<!--                    </a-select>-->
<!--                  </a-form-model-item>-->
<!--                </a-col>-->
<!--                <a-col  :span="13">-->
<!--                  <a-form-model-item label="目标题型分项" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="examPaperProjectIdtemId">-->
<!--                    &lt;!&ndash;              <j-dict-select-tag v-model="model.exaPapProItemCode" placeholder="选择目标题型分项"&ndash;&gt;-->
<!--                    &lt;!&ndash;                                 :dictCode='changePaperItemParams.examPaperProjectItemIdSelect'/>&ndash;&gt;-->
<!--                    <a-select v-model="speedAddStandardItemModel.exaPapProItemCode" placeholder="选择对应的目标题型分项"-->
<!--                              :getPopupContainer="(target) => target.parentNode">-->
<!--                      <a-select-option v-for="speedAddStandardItemModel in paperProjectItemListData" :key="item.value">{{ item.label }}</a-select-option>-->
<!--                    </a-select>-->
<!--                  </a-form-model-item>-->
<!--                </a-col>-->

<!--                <a-col :span="12">-->
<!--                  <a-form-model-item label="标准Code[自动填充]" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exaPapProItemCode">-->
<!--                    <a-input v-model="speedAddStandardItemModel.exaPapProItemCode" placeholder="Code来源于项目模板，自动填充"  ></a-input>-->
<!--                  </a-form-model-item>-->
<!--                </a-col>-->
                <!-- 快速生成-总分标准 -->
                <a-col :span="24" style='margin-bottom: 8px;'>
                  <div style="padding: 10px 0px 10px 0px;font-size: 15px;">
                    <span>试卷标准</span>
                    <span v-if='speedPaperData.examinationPaperFullMarks != null' style='margin-left: 50px;font-size: 15px;color: #08860f;font-weight: bold;'>试卷满分：{{ speedPaperData.examinationPaperFullMarks }} 分</span>
                    <span style='margin-left: 50px;font-weight: lighter;'>
                      <a-space direction="vertical">
                        <a-radio-group v-model:value="speedAddStandardItemModel.createStandardItemKey" name="标准生成类型"  label="标准生成类型">
                          <a-radio value="1">优良及格型</a-radio>
                          <a-radio value="2">临界线型</a-radio>
                          <a-button icon="plus" type="primary" style='background-color: #109ee3;border: none;' @click="addItemBox">总分-增加段位</a-button>
                          <a-button style='margin-left: 20px;background-color: #12b35b;border: none;' icon="plus" type="primary" @click="addItemBox2">分项-增加段位</a-button>
                        </a-radio-group>
                      </a-space>
                    </span>
                  </div>
                </a-col>
              </a-row>
              <a-row>
                <!-- 总分标准分段 -->
                <a-col :span="24" style='margin-bottom: 8px;'>
                  <div style="padding: 10px 0px 10px 0px;font-size: 15px;"><span>总分-标准分段 [分值区间 0.00 -- 1.00]% : （批量处理时时必按比例设置）</span></div>
                </a-col>
                <a-row>
                  <a-form-item v-for="(itemDomain , index ) in itemDomains" :key="itemDomain.key" style='width: 48%;margin: 10px;float: left;'>
                    <div style="background-color: #cddce8;border-radius: 4px;width: 100%;padding: 20px 0px 0px 0px;float: left;">
                      <a-col :span="8">
                        <a-form-model-item label="段位" :labelCol="labelCol" :wrapperCol="wrapperCol">
                          <a-input v-model="itemDomain.itemDomainName" placeholder="如：不及格、及格、良好、优秀"></a-input>
                        </a-form-model-item>
                      </a-col>
                      <a-col :span="5">
                        <a-form-model-item label="简称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                          <a-input v-model="itemDomain.itemDomainSubName" placeholder="如：良、优"></a-input>
                        </a-form-model-item>
                      </a-col>
                      <a-col :span="8">
                        <a-form-model-item label="取值范围" :labelCol="labelCol" :wrapperCol="wrapperCol">
                          <a-input v-model="itemDomain.itemDomainScore" placeholder="如：0 - 0.6"></a-input>
                        </a-form-model-item>
                      </a-col>
                      <a-button @click="removeItemBox(itemDomain)" type="danger">删除</a-button>
                    </div>
                  </a-form-item>
                </a-row>
                <!-- 题型（分项）标准分段 -->
                <a-col :span="24" style='margin-bottom: 8px;'>
                  <div style="padding: 10px 0px 10px 0px;font-size: 15px;">
                    <span>分项-标准分段 [分值区间 0.00 -- 1.00]% : （批量处理时时必按比例设置）</span>
                    <span  v-if="speedAddStandardItemModel.createStandardItemKey === '2'">临界线设置时，分项可以不设置</span>
                  </div>
                </a-col>
                <a-row>
                  <a-form-item v-for="(itemDomain2 , index ) in itemDomains2" :key="itemDomain2.key" style='width: 48%;margin: 10px;float: left;'>
                    <div style="background-color: #cddce8;border-radius: 4px;width: 100%;padding: 20px 0px 0px 0px;float: left;">
                      <a-col :span="8">
                        <a-form-model-item label="段位" :labelCol="labelCol" :wrapperCol="wrapperCol">
                          <a-input v-model="itemDomain2.itemDomainName" placeholder="如：不及格、及格、良好、优秀"></a-input>
                        </a-form-model-item>
                      </a-col>
                      <a-col :span="5">
                        <a-form-model-item label="简称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                          <a-input v-model="itemDomain2.itemDomainSubName" placeholder="如：良、优"></a-input>
                        </a-form-model-item>
                      </a-col>
                      <a-col :span="8">
                        <a-form-model-item label="取值范围" :labelCol="labelCol" :wrapperCol="wrapperCol">
                          <a-input v-model="itemDomain2.itemDomainScore" placeholder="如：0 - 0.6"></a-input>
                        </a-form-model-item>
                      </a-col>
                      <a-button @click="removeItemBox2(itemDomain2)" type="danger">删除</a-button>
                    </div>
                  </a-form-item>
                </a-row>
              </a-row>

<!--              <a-row v-if="speedAddStandardItemModel.createStandardItemKey === '2'">-->
<!--              </a-row>-->
            </a-modal>
          </div>
        </a-row>


        <!----------------------正常新增 -------------------->
        <a-row>
          <!-- 正常新增标准明细 -->
          <a-col :span="12" style='border-bottom: 1px solid #d9d9d9;margin-bottom: 10px;'>
            <a-form-model-item label="所属上级标准" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="achievementStandardId">
              <j-dict-select-tag type="list" v-model="model.achievementStandardId" disabled
                                 dictCode="ach_achievement_standard,achievement_standard_name,id" placeholder="请输入所属上级标准" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12" style='border-bottom: 1px solid #d9d9d9;margin-bottom: 10px;'>
            <a-form-model-item label="科目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="subjectId">
              <!--              <a-input v-model="model.subjectId" placeholder="请输入科目id"  ></a-input>-->
              <a-select v-model="model.subjectId" placeholder="请选择所属科目" disabled
                        :getPopupContainer="(target) => target.parentNode">
                <a-select-option v-for="item in subjectList" :key="item.value">{{ item.label }}</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row v-for="(item, index) in orderMainModel.mainCustomerList" :key="index" >
          <div style="width: 100%;background-color: rgb(239 239 239);border-radius: 2px;margin-top: 10px;padding-top: 10px;">
            <div><span style="font-weight: bold;font-size: 15px;margin-left: 10px;color: #00A0E9;"> 分项标准: {{ index + 1 }}</span></div>
          <a-row>
            <!-- 分项下拉 -->
            <a-col  :span="12">
              <a-form-model-item label="所属考试" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="examinationId">
                <j-dict-select-tag v-model="changePaperItemParams.examinationId" @change='examinationIdChange' placeholder="选择所属考试" dictCode="ach_examination,examination_name,id"/>
              </a-form-model-item>
            </a-col>
            <a-col  :span="12">
              <a-form-model-item label="目标试卷" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="examinationPaperId">
                <a-select v-model="changePaperItemParams.examinationPaperId" placeholder="选择对应的目标试卷"
                          :getPopupContainer="(target) => target.parentNode" @change='examinationPaperIdChange'>
                  <a-select-option v-for="item in paperListData" :key="item.value">{{ item.label }}</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col  :span="12">
              <a-form-model-item label="标准应用类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standardItemKey">
<!--                <a-select v-model="item.standardItemKey" placeholder="选择标准应用类型" >-->
<!--                  <a-select-option value="1">应用于题型分项</a-select-option>-->
<!--                  <a-select-option value="2">应用于总分总项</a-select-option>-->
<!--                </a-select>-->
                <a-space direction="vertical">
                  <a-radio-group v-model:value="item.standardItemKey" name="标准应用类型"  label="标准应用类型">
                    <a-radio value="1" @change="item.exaPapProItemCode = ''">应用于分项</a-radio>
                    <a-radio value="2" @change="item.exaPapProItemCode = changePaperItemParams.examinationPaperId">应用于总分</a-radio>
                  </a-radio-group>
                </a-space>
              </a-form-model-item>
            </a-col>
            <a-col  :span="12">
              <a-form-model-item v-if="item.standardItemKey === '1'" label="目标题型分项" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="examPaperProjectIdtemId">
  <!--              <j-dict-select-tag v-model="model.exaPapProItemCode" placeholder="选择目标题型分项"-->
  <!--                                 :dictCode='changePaperItemParams.examPaperProjectItemIdSelect'/>-->
                <a-select v-model="item.itemCode" placeholder="选择对应的目标题型分项" @change="item.exaPapProItemCode = item.itemCode"
                          :getPopupContainer="(target) => target.parentNode">
                  <a-select-option v-for="item in paperProjectItemListData" :key="item.value">{{ item.label }}</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item  label="标准Code[自动]" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exaPapProItemCode">
                <a-input v-model="item.exaPapProItemCode" placeholder="Code来源于项目模板，自动填充"  ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item label="标准分项编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemCode">
                <a-input v-model="item.standItemCode" placeholder="请输入标准分项编码"  ></a-input>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="12">
              <a-form-model-item label="标准分项名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemName">
                <a-input v-model="item.standItemName" placeholder="请输入标准分项名称(不及格、及格、良好、优秀等）"  ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item label="标准分项简称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemAliasname">
                <a-input v-model="item.standItemAliasname" placeholder="请输入标准分项目别名简称"  ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item label="分数最低分(含)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemLowestScore">
                <a-input-number v-model="item.standItemLowestScore" placeholder="请输入分数最低分(含)" style="width: 100%" />
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item label="分数最高分(不含)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemHighestScore">
                <a-input-number v-model="item.standItemHighestScore" placeholder="请输入分数最高分(不含)" style="width: 100%" />
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item label="分数最低百分比(含)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemLowestRate">
                <a-input-number v-model="item.standItemLowestRate" placeholder="请输入分数最低分率百分比(含)" style="width: 100%" />
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item label="分数最高百分比(不含)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemHighestRate">
                <a-input-number v-model="item.standItemHighestRate" placeholder="请输入分数最高分率百分比(不含)" style="width: 100%" />
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item label="评分实际得分" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemActualScore">
                <a-input-number v-model="item.standItemActualScore" placeholder="请输入标准分项评分实际得分" style="width: 100%" />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="24" style='border-top: 1px solid #d9d9d9;padding-top: 10px;padding-bottom: 10px;'>
             <div style='color: rgba(0, 0, 0, 0.85);'>评分特殊限制</div>
            </a-col>
            <a-col :span="12" >
              <a-form-model-item label="特殊限制状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItSpecialRestrictions">
  <!--              <a-input-number v-model="model.standItSpecialRestrictions" placeholder="请输入特殊限制状态" style="width: 100%" />-->
                <j-dict-select-tag type="list" v-model="item.standItSpecialRestrictions"
                                   dictCode="stand_it_special_restrictions" placeholder="请输入特殊限制状态" />
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item label="限制数最小值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sitemSpecRestMinvalue">
                <a-input-number v-model="item.sitemSpecRestMinvalue" placeholder="请输入特殊限制数最小值（含即大于等于或等于）" style="width: 100%" />
                <span style='line-height: 20px;float: left;font-size: 10px;color: #c21313;'>含即大于等于或等于</span>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item label="限制数最大值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sitemSpecRestMaxvalue">
                <a-input-number v-model="item.sitemSpecRestMaxvalue" placeholder="请输入特殊限制数最大值（不含或小于）" style="width: 100%" />
                <span style='line-height: 20px;float: left;font-size: 10px;color: #c21313;'>不含或小于</span>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="12" style='border-top: 1px solid #d9d9d9;padding-top: 20px;'>
              <a-form-model-item label="项目序号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemOrder">
                <a-input-number v-model="item.standItemOrder" placeholder="请输入项目序号" style="width: 100%" />
              </a-form-model-item>
            </a-col>
            <a-col :span="12" style='border-top: 1px solid #d9d9d9;padding-top: 20px;'>
              <a-form-model-item label="上级项目（没有:填0）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemFatherId">
                <a-input v-model="item.standItemFatherId = defaultText.standItemFatherId" placeholder="请输入上级项目id"  ></a-input>
              </a-form-model-item>
            </a-col>
<!--            <a-col :span="12">-->
<!--              <a-form-model-item label="是否启用" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="izOpen">-->
<!--                <j-dict-select-tag type="list" v-model="item.izOpen = defaultText.izOpen"-->
<!--                                   dictCode="iz_open" placeholder="请选择是否启用" />-->
<!--              </a-form-model-item>-->
<!--            </a-col>-->
<!--            <a-col :span="12">-->
<!--              <a-form-model-item label="所属部门编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sysOrgCode">-->
<!--  &lt;!&ndash;              <a-input v-model="model.sysOrgCode" placeholder="请输入所属部门编码"  ></a-input>&ndash;&gt;-->
<!--                <a-select v-model="item.sysOrgCode = defaultText.sysOrgCode" placeholder="请选择所属部门"-->
<!--                          :getPopupContainer="(target) => target.parentNode">-->
<!--                  <a-select-option v-for="item in departDataList" :key="item.value">{{ item.label }}</a-select-option>-->
<!--                </a-select>-->
<!--              </a-form-model-item>-->
<!--            </a-col>-->
  <!--          <a-col :span="24">-->
  <!--            <a-form-model-item label="创建人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createBy">-->
  <!--              <a-input v-model="model.createBy" placeholder="请输入创建人"  ></a-input>-->
  <!--            </a-form-model-item>-->
  <!--          </a-col>-->
  <!--          <a-col :span="24">-->
  <!--            <a-form-model-item label="修改人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="updateBy">-->
  <!--              <a-input v-model="model.updateBy" placeholder="请输入修改人"  ></a-input>-->
  <!--            </a-form-model-item>-->
  <!--          </a-col>-->

            <a-col :span="24">
              <a-form-model-item style="text-align: center;width: 100%">
                <a-button type="dashed" style="margin-top: 10px" @click="delRowCustom(index)">
                  <a-icon type="minus-circle" /> 删除标准
                </a-button>
              </a-form-model-item>
            </a-col>
          </a-row>
          </div>
        </a-row>
        <a-button type="dashed" style="width: 98%;margin-top: 10px" @click="addRowCustom()">
          <a-icon type="plus" /> 添加题型标准
        </a-button>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import { httpAction, getAction, postAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import { getDepartDataList } from '@api/commonAPI'
  import { getSubjectList,getAchAchievStandardList } from '@api/achievementCommonAPI'

  export default {
    name: 'AchAchieveStandardItemForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 8 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 13 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/achachievestandarditem/achAchieveStandardItem/add",
          edit: "/achachievestandarditem/achAchieveStandardItem/edit",
          queryById: "/achachievestandarditem/achAchieveStandardItem/queryById",

          //试卷list
          paperList: "/achexaminationpaper/achExaminationPaper/paperList",
          //试卷题型分项list
          paperProjectItemList: "/achexampaperprojectitem/achExamPaperProjectItem/paperProjectItemList",

          //快速新增标准明细
          getPaperData: "/achexaminationpaper/achExaminationPaper/queryById",//查询试卷
          getPaperProjectItemData: "/achexampaperprojectitem/achExamPaperProjectItem/paperProjectItemList",//查询试卷分项
          speedAddStandardItem: "/achachievestandarditem/achAchieveStandardItem/speedAddStandardItem",//快速添加提交
        },
        departDataList: [],
        subjectList: [],
        achAchievStandardList: [],
        //标准明细的分项code联动下拉参数
        paperListData: [],//试卷数据
        paperProjectItemListData: [],//题型分项数据
        changePaperItemParams: {
          examinationId: "", //考试id
          examinationPaperId: "",//试卷id
          examPaperProjectIdtemId: "",//分项（大题型）id
        },

        //动态增加表单
        orderMainModel: {
          mainCustomerList: [{}],
          jeecgOrderTicketList: [{}]
        },
        //新增设置默认值
        defaultText: {
          achievementStandardId : "",
          subjectId : "",
          standItemOrder : null,
          standItemFatherId : "0", //上级项目
          sysOrgCode : "" ,
          izOpen : 1, //是否启用 （1是 2否）
          delFlag : 0, //是否删除 默认（未删除）
        },
        //code字段自动填充
        // standardItemKey : "1",//1:应用于题型分项（默认） 2:应用于总分总项
        standardItemCode : "",//根据应用类型 code填充及设置


        //快速新增标准明细
        speedAddStandardItemVisible: false,
        speedAddStandardItemModel: {
          createStandardItemKey: "1",//快速标准生成类型
        },//快速新增model
        //快速生成基本数据
        speedPaperData: [],//试卷
        speedPaperProjectItemData: [],//试卷题型
        itemDomains: [],//总分-段类型数据1
        itemDomains2: [],//题型-分段类型数据2

      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
      this.getAchAchievStandardData();
      this.getDepartData();
      this.getSubjectData();
    },
    methods: {
      examinationIdChange(){
        this.getAchExamPaper();//调用查询试卷方法
        this.changePaperItemParams.examinationPaperId = "";
        this.changePaperItemParams.examPaperProjectIdtemId = "";
      },
      examinationPaperIdChange(){
        this.getAchExamPaperProjectItem();//调用查询试卷分项题型方法
        this.changePaperItemParams.examPaperProjectIdtemId = "";
      },

      add (record) {
        //动态表单连续新增设置默认值
        this.modelDefault.achievementStandardId = record.id
        this.modelDefault.subjectId = record.subjectId
        this.modelDefault.standItemFatherId = this.defaultText.standItemFatherId,
        this.modelDefault.standItemOrder = this.defaultText.standItemOrder,
        this.modelDefault.sysOrgCode = record.sysOrgCode
        this.modelDefault.izOpen = this.defaultText.izOpen,
        this.modelDefault.delFlag = this.defaultText.delFlag,

        // this.modelDefault.achievementStandardId = record.id
        // this.modelDefault.subjectId = record.subjectId
        // this.modelDefault.standItemOrder = 1; //项目序号
        // this.modelDefault.standItemFatherId = "0"; //上级项目
        // this.modelDefault.sysOrgCode = record.sysOrgCode
        // this.modelDefault.izOpen = 1; //是否启用 （1是 2否）
        // this.modelDefault.delFlag = 0; //是否删除 默认（未删除）
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);

        this.defaultText.achievementStandardId = record.id
        this.defaultText.subjectId = record.subjectId
        this.defaultText.exaPapProItemFatherId = record.exaPapProItemFatherId,
        this.defaultText.standItemOrder = record.standItemOrder,
        this.defaultText.sysOrgCode = record.sysOrgCode
        this.defaultText.izOpen = record.izOpen,
        this.defaultText.delFlag = record.delFlag,

        this.orderMainModel.mainCustomerList.length = 0;//编辑时设默认表单为0
        this.orderMainModel.mainCustomerList.push(this.model);//push后表单为当前编辑的一个

        this.visible = true;
      },
      submitForm () {
        //动态增加表单数据，循环依次新增
        if (this.orderMainModel.mainCustomerList.length > 0) {
          this.orderMainModel.mainCustomerList.forEach((item, index) => {
            this.model = item
            //提交表单数据
            const that = this;
            // 触发表单验证
            this.$refs.form.validate(valid => {
              if (valid) {
                that.confirmLoading = true;
                let httpurl = '';
                let method = '';
                if (!this.model.id) {
                  //设置默认值
                  this.model.achievementStandardId = this.modelDefault.achievementStandardId,//上级标准
                  this.model.subjectId = this.modelDefault.subjectId,//科目
                  this.model.sysOrgCode = this.modelDefault.sysOrgCode,//部门编码

                  httpurl += this.url.add;
                  method = 'post';
                } else {
                  httpurl += this.url.edit;
                  method = 'put';
                }
                httpAction(httpurl, this.model, method).then((res) => {
                  if (res.success) {
                    that.$message.success(res.message);
                    that.$emit('ok');
                  } else {
                    that.$message.warning(res.message);
                  }
                }).finally(() => {
                  that.confirmLoading = false;
                })
              }
            })
          });
        }
        //提交完后清空缓存动态表单数据，一面影响下次数据
        this.orderMainModel.mainCustomerList = [{}]
      },
      async getAchAchievStandardData() {
        let res = await getAchAchievStandardList()
        this.achAchievStandardList = []
        res.result.records.forEach(item => {
          this.achAchievStandardList.push({
            label: item.achievementStandardName,
            value: item.id
          })
        })
      },
      async getDepartData() {
        let res = await getDepartDataList()
        this.departDataList = []
        res.result.forEach(item => {
          this.departDataList.push({
            label: item.departName,
            value: item.orgCode
          })
        })
      },
      async getSubjectData() {
        let res = await getSubjectList()
        this.subjectList = []
        res.result.records.forEach(item => {
          this.subjectList.push({
            label: item.subjectName,
            value: item.id
          })
        })
      },

      //查询试卷
      getAchExamPaper(){
        let achExaminationPaper = {
          examinationId : this.changePaperItemParams.examinationId
        }
        getAction(this.url.paperList,achExaminationPaper).then((res) => {
          if (res.success){
            this.paperListData = []
            res.result.forEach(item => {
              this.paperListData.push({
                label: item.examinationPaperName,
                value: item.id
              })
            })
          }
        });
      },
      //查询试卷题型分项，通过试卷id查询
      getAchExamPaperProjectItem(){
        let achExamPaperProjectItem = {
          examinationPaperId : this.changePaperItemParams.examinationPaperId,//试卷ID
        }
        getAction(this.url.paperProjectItemList,achExamPaperProjectItem).then((res) => {
          if (res.success) {
            this.paperProjectItemListData = []
            res.result.forEach(item => {
              this.paperProjectItemListData.push({
                label: item.exaPapProItemName,
                value: item.id
              })
            })
          }
        });
      },

      //动态增加表单
      // 初始化
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.orderMainModel.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
              method = 'put';
            }
            httpAction(httpurl,this.orderMainModel,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })

          }
        })
      },
      handleCancel () {
        this.close()
      },
      addRowCustom () {
        this.orderMainModel.mainCustomerList.push({});
        this.$forceUpdate();
      },
      delRowCustom (index) {
        console.log(index)
        let all = this.orderMainModel
        all['mainCustomerList'].splice(index,1);
        this.orderMainModel.mainCustomerList.splice(index,1);
        this.$forceUpdate();
      },
      addRowTicket () {
        this.orderMainModel.jeecgOrderTicketList.push({});
        // console.log(this.orderMainModel.jeecgOrderTicketList)
        this.$forceUpdate();
      },
      delRowTicket (index) {
        // console.log(index)
        let all = this.orderMainModel
        all['jeecgOrderTicketList'].splice(index,1);
        this.orderMainModel.jeecgOrderTicketList.splice(index,1);
        this.$forceUpdate();
      },

      //=========================
      //快速新增试卷后 自动获取试卷题型的相应分数，并自动生产相应段位的分数区间
      speedAddPaperIdGetScoreChange(paperId){
        let param = {
          id : paperId
        }
        getAction(this.url.getPaperData,param).then((res) => {
          if (res.success){
            this.speedPaperData = res.result
            console.log(res)
          }else {
          }
        });
      },
      //快速新增标准明细
      speedAddtandardItem(){
        this.speedAddStandardItemVisible = true;
      },
      //快速新增数据 提交OK
      speedAddStandardItemOk(){
        if (this.speedAddStandardItemModel.achievementStandardId == null || this.speedAddStandardItemModel.achievementStandardId == ''){
          return alert("请先选择上级标准")
        }
        if (this.changePaperItemParams.examinationPaperId == null || this.changePaperItemParams.examinationPaperId == ''){
          return alert("请先选择对应的试卷")
        }
        let params = {
          standardId : this.speedAddStandardItemModel.achievementStandardId,//上级的标准
          subjectId : this.speedAddStandardItemModel.subjectId,//科目
          examinationPaperId : this.changePaperItemParams.examinationPaperId,//对应的试卷
          paperStandardItem : JSON.stringify(this.itemDomains),//总分分段参数
          paperItemStandardItem : JSON.stringify(this.itemDomains2),//题型分段参数
        }
        postAction(this.url.speedAddStandardItem,params).then((res) => {
          if (res.success){
            this.$message.success(res.message)
            this.speedAddStandardItemVisible = false
          }else {
            this.$message.error(res.message)
          }
        });
        this.itemDomains = [];//清空
        this.itemDomains2 = [];//清空
      },
      //快速新增 取消提交
      speedAddStandardItemVisibleCancel(){
        this.speedAddStandardItemVisible = false;
      },

      //总分-增加box
      addItemBox(){
        this.itemDomains.push({
          key: Date.now(),
          itemDomainName: "",//总分-不及格、及格、良好、优秀
          itemDomainSubName: "",//简称 - 良、优
          itemDomainScore: '0.00-0.00'
        })
      },
      //总分-删除box
      removeItemBox(item) {
        let index = this.itemDomains.indexOf(item)
        if (index != -1) {
          this.itemDomains.splice(index, 1)
        }
      },
      //题型-增加box
      addItemBox2(){
        this.itemDomains2.push({
          key: Date.now(),
          itemDomainName: "",//题型-不及格、及格、良好、优秀
          itemDomainSubName: "",//简称 - 良、优
          itemDomainScore: '0.00-0.00'
        })
      },
      //题型-删除box
      removeItemBox2(item) {
        let index = this.itemDomains2.indexOf(item)
        if (index != -1) {
          this.itemDomains2.splice(index, 1)
        }
      }

    }
  }
</script>